from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

import sys

sys.path.append(r'..')

from web_base.base_page_asset import BasePage


class PersonalPage(BasePage):
    url = r'/bsams/front/asset_user/user_info.do'
    # 修改电话号
    personal_loc = (By.XPATH, '//*[@id="leftmenu_asset_user"]/div[1]/a/img')
    personal_tel_loc = (By.ID, 'phone')
    personal_ok_loc = (By.CLASS_NAME, 'button_fujian')
    # 修改密码
    updatepwd_btn_loc = (By.LINK_TEXT, '修改密码')
    oldpwd_loc = (By.ID, 'oldPassword')
    newpwd_loc = (By.ID, 'newPassword1')
    newpwd2_loc = (By.ID, 'newPassword2')
    pwd_ok_loc = (By.XPATH, '//*[@id="cboxLoadedContent"]/div/div/div[2]/div[4]/div[1]')

    def personal_tel(self, tel):
        self.open()
        sleep(1)
        self.ele_click(self.personal_loc)
        sleep(1)
        self.ele_clear(self.personal_tel_loc)
        sleep(1)
        self.input_ele(self.personal_tel_loc, tel)
        sleep(1)
        self.ele_click(self.personal_ok_loc)
        sleep(2)
        text = self.get_alert_text()
        self.alert.click()
        return text

    def personal_pwd(self, oldpwd, newpwd, newpwd1):
        self.open()
        sleep(1)
        self.ele_clear(self.oldpwd_loc)
        sleep(1)
        self.input_ele(self.oldpwd_loc, oldpwd)
        sleep(1)
        self.ele_clear(self.newpwd_loc)
        sleep(1)
        self.input_ele(self.newpwd_loc, newpwd)
        sleep(1)
        self.ele_clear(self.newpwd2_loc)
        sleep(1)
        self.input_ele(self.newpwd2_loc, newpwd1)
        sleep(1)
        self.ele_click(self.pwd_ok_loc)
        sleep(2)
        text = self.get_alter_text()
        self.alert_click()
        return text
